﻿Type=Class
Version=6
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
'支付类
Sub Class_Globals
	Private act As Activity
	Private dtot As Double
	Public pid As payItem
	Private apitype As Int
	Private px As Pingxx

End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(ac As Activity)
	act=ac
	px.init("px",True)
End Sub
public Sub SubmitOrder(kcid As String,totmoney As String,keshi As String,yhqid As String,kc_mode As String,addr As String,tpid As payItem)
	comm.showProgress("正在提交订单请稍后")
	Dim parms() As String
	dtot=totmoney
	pid=tpid
	If yhqid.Length>0 Then
		parms=Array As String("yhj_id",yhqid,"kc_mode",kc_mode,"id",kcid,"money",totmoney,"keshi",keshi,"addr",addr)
	Else	
		parms=Array As String("yhj_id","0","kc_mode",kc_mode,"id",kcid,"money",totmoney,"keshi",keshi,"addr",addr)
	End If
	ParseHelper.doPostReqArr(Me,"subord",comm.getApi(comm.apiIdx.SUBMITORDER),parms,"")
	
End Sub
public Sub SubmitJinqiOrder(tecid As String,ratestr As String)
	comm.showProgress("正在提交锦旗订单请稍后")
	Dim parms() As String=Array As String("remark",ratestr,"money",100,"js_id",tecid)
	ParseHelper.doPostReqArr(Me,"subjqord",comm.getApi(comm.apiIdx.SUBJINQIORDER),parms,"")
	
End Sub
'0=balance,1=alipay,2=wx
Public Sub subpay(sn As String,paypwd As String,apitype1 As Int)
	comm.showProgress("正在提交支付请求")
	Dim paytype As String
	Dim parm() As String
	Select apitype1
	Case 0
		paytype="balance"
	Case 1
		paytype="alipay"
	Case 2
		paytype="wx"
	End Select
	apitype=apitype1
	If apitype1=0 Then
		parm=Array As String("order_sn",sn,"pay_pwd",paypwd,"api_type",paytype)
		ParseHelper.doPostReqArr(Me,"subpayyue",comm.getApi(comm.apiIdx.REQINAPPPAY),parm,"")
	Else
		parm=Array As String("order_sn",sn,"api_type",paytype)
		ParseHelper.doPostReqArr(Me,"subpay3",comm.getApi(comm.apiIdx.REQINAPPPAY),parm,"")
	End If
	'ParseHelper.doPostReqArr(Me,"subpay",comm.getApi(comm.apiIdx.REQINAPPPAY),parm,"")
End Sub
Public Sub subcharge(tpid As payItem,apitype1 As Int)
	comm.showProgress("正在提交支付请求")
	Dim paytype As String
	Select apitype1
	Case 0
		paytype="balance"
	Case 1
		paytype="alipay"
	Case 2
		paytype="wx"
	End Select
	apitype=apitype1
	ParseHelper.doPostReqArr(Me,"subcharge",comm.getApi(comm.apiIdx.REQCHARGE2),Array As String("money",tpid.money,"order_sn",tpid.pid,"is_teach",0,"api_type",paytype),"")
End Sub
Sub JobDone(thj As HttpJob)
	ProgressDialogHide
	'px.createPayment($"{ "id": "ch_b9SSSCnPCW5SjTeHy5rPmjjP", "object": "charge", "created": 1461921844, "livemode": false, "paid": false, "refunded": false, "app": "app_WX54mTnn5uDKGmv1", "channel": "alipay", "order_no": "201604295556504901", "client_ip": "127.0.0.1", "amount": 1, "amount_settle": 1, "currency": "cny", "subject": "测试支付", "body": "假装买了个东西", "extra": {}, "time_paid": null, "time_expire": 1462008244, "time_settle": null, "transaction_no": null, "refunds": { "object": "list", "url": "/v1/charges/ch_b9SSSCnPCW5SjTeHy5rPmjjP/refunds", "has_more": false, "data": [] }, "amount_refunded": 0, "failure_code": null, "failure_msg": null, "metadata": {}, "credential": { "object": "credential", "alipay": { "orderInfo": "_input_charset=\"utf-8\"&body=\"假装买了个东西\"&it_b_pay=\"2016-04-30 17:24:04\"¬ify_url=\"https%3A%2F%2Fapi.pingxx.com%2Fnotify%2Fcharges%2Fch_b9SSSCnPCW5SjTeHy5rPmjjP\"&out_trade_no=\"201604295556504901\"&partner=\"2008114626098910\"&payment_type=\"1\"&seller_id=\"2008114626098910\"&service=\"mobile.securitypay.pay\"&subject=\"测试支付\"&total_fee=\"0.01\"&sign=\"ZkxXekRTU21IYTVTYkRLMFdEYW45YURT\"&sign_type=\"RSA\"" } }, "description": null }"$)
	If thj.Success Then
		Dim str As String=thj.GetString
		If str.Length<1 Then Return
		Dim nr As netRes=ParseHelper.getStatusData(str)
		comm.L(str)
		Select thj.JobName
		Case "subord"
			If nr.nCode=200 Then
				comm.TL("订单提交成功，进入支付流程")	
				Dim parser As JSONParser 
				parser.Initialize(str) 
				Dim root As Map = parser.NextObject 
				Dim data As String = root.Get("data") 
				Dim order_sn As String = root.Get("order_sn") 
				Dim status As String = root.Get("status") 
				pid.pid=order_sn
				g_store.put("pid",pid)
				StartActivity(actSelectPayMethod)
				act.Finish
			Else
				comm.TL("订单提交失败:"&nr.sData)
			End If
		Case "subjqord"
			If nr.nCode=200 Then
				comm.TL("锦旗订单提交成功，进入支付流程")	
				Dim parser As JSONParser 
				parser.Initialize(str) 
				Dim root As Map = parser.NextObject 
				Dim data As String = root.Get("data") 
				Dim order_sn As String = root.Get("order_sn") 
				Dim status As String = root.Get("status") 
				pid.pid=order_sn
				pid.money=100
				g_store.put("pid",pid)
				StartActivity(actSelectPayMethod)
				act.Finish
			Else
				comm.TL("锦旗订单提交失败:"&nr.sData)
			End If
		Case "subpayyue"
			If nr.nCode=200 Then
				If apitype=0 Then
					comm.TL("支付成功")
					If act<>Null Then 	act.Finish
				End If
			Else
				comm.TL(nr.sData)
			End If
		Case "subpay3"
			If nr.nCode=300 Then
				Dim parser As JSONParser 
				parser.Initialize(str) 
				Dim root As Map = parser.NextObject 
				Dim m As Map=root.Get("data")
				Dim jsg As JSONGenerator
				jsg.Initialize(m)
				Dim sData As String=jsg.ToString
				Dim status As String = root.Get("status") 
				
				'sData=$"{"id":"ch_1WHizLPuTCKCrnX9mDerXzbP","object":"charge","created":1470921877,"livemode":false,"paid":false,"refunded":false,"app":"app_i1yXz1WHiPOO5SW9","channel":"alipay","order_no":"57ac7c9547a83","client_ip":"49.118.232.53","amount":8,"amount_settle":8,"currency":"cny","subject":"一对一视频课程示范","body":"一对一视频课程示范","extra":[],"time_paid":null,"time_expire":1471008277,"time_settle":null,"transaction_no":null,"refunds":{"object":"list","url":"/v1/charges/ch_1WHizLPuTCKCrnX9mDerXzbP/refunds","has_more":false,"data":[]},"amount_refunded":0,"failure_code":null,"failure_msg":null,"metadata":[],"credential":{"object":"credential","alipay":{"orderInfo":"_input_charset=\"utf-8\"&body=\"一对一视频课程示范\"&it_b_pay=\"2016-08-12 21:24:37\"&notify_url=\"https%3A%2F%2Fapi.pingxx.com%2Fnotify%2Fcharges%2Fch_1WHizLPuTCKCrnX9mDerXzbP\"&out_trade_no=\"57ac7c9547a83\"&partner=\"2008376631538708\"&payment_type=\"1\"&seller_id=\"2008376631538708\"&service=\"mobile.securitypay.pay\"&subject=\"一对一视频课程示范\"&total_fee=\"0.08\"&sign=\"SG01ZTVDbUh5VFM0NXliUEdPbUQ0ZUhP\"&sign_type=\"RSA\""}},"description":"购买课程"}"$
				Log("data:"&CRLF&sData)
				px.createPayment(sData)
			else if nr.nCode=200 Then
				comm.TL("支付成功")
				act.Finish
			Else
				comm.TL("支付失败:"&nr.sData)
				
			End If
		Case "subcharge"
			If nr.nCode=200 Then
				If apitype=0 Then
					comm.TL("支付成功")
					If act<>Null Then 	act.Finish
				Else
					Dim parser As JSONParser 
					parser.Initialize(str) 
					Dim root As Map = parser.NextObject 
					Dim m As Map=root.Get("data")
					Dim jsg As JSONGenerator
					jsg.Initialize(m)
					Dim sData As String=jsg.ToString
					Dim status As String = root.Get("status") 
					Log("data:"&CRLF&sData)
					px.createPayment(sData)
					
				End If
			Else
				comm.TL("支付失败:"&nr.sData)
				
			End If
		End Select

	Else
		comm.TL("网络错误:"&thj.JobName&thj.ErrorMessage)
	End If
	thj.Release
End Sub
Sub px_paymentresult(result As String,extramsg As String,errmsg As String)
'	/* 处理返回值
'     * "success" - 支付成功
'     * "fail"    - 支付失败
'     * "cancel"  - 取消支付
'     * "invalid" - 支付插件未安装（一般是微信客户端未安装的情况）
'     */
	comm.L(result)
	Select result.ToLowerCase
	Case "success"
		comm.TL("支付成功")
		act.Finish
	Case Else
		comm.TL("支付失败:"&result	&extramsg&errmsg)
	End Select
	
End Sub